package com.sunjob.mrotech.controller;

import com.sunjob.common.domain.tech.RepairProcess2;
import com.sunjob.common.domain.tech.RepairProcess2DO;
import com.sunjob.common.domain.tech.TransShape2;
import com.sunjob.common.mroAnno.ControllerLog;
import com.sunjob.common.mroAnno.LogModuleType;
import com.sunjob.common.result.Result;
import com.sunjob.mrotech.mapper.RepairProcess2Mapper;
import com.sunjob.mrotech.server.RepairProcess2Server;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author : xiaozhoutongxue
 * @date : 2022/8/8 10:46
 */
@CrossOrigin
@RestController
@Api(tags = "二级修程工艺处理")
public class RepairProcess2Controller {
    @Autowired
    RepairProcess2Server repairProcess2Server;
    @Autowired
    RepairProcess2Mapper repairProcess2Mapper;

    @ApiOperation("获得拥有修程工艺的前几个二级构型")
    @GetMapping("/getRepairProcess2ByLimit3")
    public Result getRepairProcess2ByLimit3() {
        List<TransShape2> repairProcess2 = repairProcess2Server.getRepairProcess2ByLimit3();
        return repairProcess2.size()!=0 ?Result.ok(repairProcess2, "ok"):Result.build(null,211,"未找到修程工艺");
    }

    @ApiOperation("根据二级构型id获得修程工艺")
    @GetMapping("/getRepairProcess2ById")
    public Result getRepairProcess2ById(@RequestParam Long shape2Id) {
        RepairProcess2 repairProcess2 = repairProcess2Server.getRepairProcess2ByShape2Id(shape2Id);
        return repairProcess2!=null ?Result.ok(repairProcess2, "ok"):Result.build(null,211,"未找到修程工艺");
    }
    @ApiOperation("根据二级修程工艺id获得修程工艺")
    @GetMapping("/getRepairProcess2ByRepair2Id")
    public Result getRepairProcess2ByRepair2Id(@RequestParam Long repairProcess2Id) {
        RepairProcess2 repairProcess2 = repairProcess2Mapper.getRepairProcess2ById(repairProcess2Id);
        return repairProcess2!=null ?Result.ok(repairProcess2, "ok"):Result.build(null,211,"未找到修程工艺");
    }

    @ApiOperation("新增二级修程工艺")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PostMapping("/insertRepairProcess2")
    public Result insertRepairProcess2(@RequestBody RepairProcess2 repairProcess2) {
        String flag = repairProcess2Server.insertRepairProcess2(repairProcess2);
        return "true".equals(flag) ? Result.ok(null, "新增成功") : Result.fail(flag);
    }

    @ApiOperation("绑定二级修程工艺通过二级构型id")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PutMapping("/bindRepairProcessByShape2Id")
    public Result bindRepairProcessByShape2Id(@RequestParam Long shape2Id,@RequestParam Long repairProcess2Id){
        Boolean flag = repairProcess2Server.bindRepairProcessByShape2Id(shape2Id,repairProcess2Id);
        return flag  ? Result.ok(null, "绑定成功") : Result.fail("绑定失败");
    }

    @ApiOperation("根据二级修程工艺id删除一个二级修程工艺")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @DeleteMapping("/deleteRepairProcess2ById")
    public Result deleteRepairProcess2ById(@RequestParam Long repairProcess2Id){
        String res = repairProcess2Server.deleteRepairProcess2ById(repairProcess2Id);
        return "true".equals(res) ? Result.ok(null, "成功") : Result.build(null,210,res);
    }

    @ApiOperation("更新一个二级修程工艺(小修改：不涉及到步骤改动)")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PutMapping("/uptateRepairProcess2Small")
    public Result uptateRepairProcess2Small(@RequestBody RepairProcess2DO repairProcess2DO){
        Boolean flag = repairProcess2Server.uptateRepairProcess2Small(repairProcess2DO);
        return flag  ? Result.ok(null, "成功") : Result.fail("失败");
    }

    @ApiOperation("更新一个二级修程工艺(大修改：涉及到步骤改动，更新版本号)")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PutMapping("/uptateRepairProcess2Big")
    public Result uptateRepairProcess2Big(@RequestBody RepairProcess2 repairprocess2){
        Boolean flag = repairProcess2Server.uptateRepairProcess2Big(repairprocess2);
        return flag  ? Result.ok(null, "成功") : Result.fail("失败");
    }

}
